<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="jypath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="${jypath}/static/css/system/bootstrap/bootstrap.min.css"/>
		<script type="text/javascript" src="${jypath}/static/js/jquery/jquery-2.0.3.min.js"></script>
		<script type="text/javascript" src="${jypath}/static/plugins/layer/2.1/layer.js"></script>
	</head>
	<body>
		<div class="container">
			<div class="row">
			    <div class="col-xs-offset-1 col-xs-10">
				<form class="form-horizontal" id="distributionForm">
					<div class="form-group">
						<label class="col-xs-4 control-label"><font style="color:red">*</font>关联流程:</label>
						<div class="col-xs-8">
							<select class="form-control" id="allProcdef">
								<option value="">全部</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<div class="col-xs-5">
						</div>
						<div class="col-xs-6">
							<button type="button" class="btn btn-default" onclick="saveDistribution()">确定</button>
							<button type="button" class="btn btn-default" onclick="canelDistribution()">取消</button>
						</div>
									
					</div>
				</form>
				</div>
			</div>
		</div>
	</body>
<script type="text/javascript">
var id="${id}";
var procdefId="${procdefId}";
var layerIndex = parent.layer.getFrameIndex(window.name); 
$(function () {
	loadAllProcdef();
	//loadMerchantProcdef();
});
function canelDistribution(){
	 parent.layer.close(layerIndex);
}
function saveDistribution(){
	var allProcdef=$("#allProcdef").val();
	if(allProcdef==null || allProcdef==""){
		layer.alert('请选择关联流程！')
		return;
	}
	$.ajax({
		type: 'post',
        url: "${jypath}/estate/projectProcdef/edit",
	    data: {
	    	id:id,
	    	procdefId:allProcdef
	    },
	    dataType:'json',
	    async: false,
	    success: function(data){
	    	if(data.res=="1"){
	    		parent.listVue.getList();
		    	parent.layer.closeAll();
	    	}else if(data.res=="100"){
	    		layer.alert("权限不足！")
	    	}else{
	    		layer.tips(data.resMsg, '#allProcdef', {
	    			  tips: [3, 'red'],
	    			  time: 3000
	    		});
	    	}
	    	
	    	
	    }
	});
	
}
function loadMerchantProcdef(){
	$.ajax({
		type: 'post',
        url: "${jypath}/system/mearchantProcdef/queryMearchantProcdef",
	    data: {},
	    dataType:'json',
	    async: false,
	    success: function(data){
			var obj=data.obj;
			var allRole='<option value="">请选择</option>';
			$.each(obj,function(n,v) {
				if(v.procdefId==procdefId){
					allRole=allRole+'<option selected value="'+v.procdefId+'">'+v.procdefName+'</option>';
				}else{
					allRole=allRole+'<option value="'+v.procdefId+'">'+v.procdefName+'</option>';
				}
				
			});
			$("#allProcdef").empty();
			$("#allProcdef").append(allRole);
	    	
	    }
	});
}
function loadAllProcdef(){
	//商户拥有流程
	var url="${jypath}/system/mearchantProcdef/queryMearchantProcdef";
	//系统部署流程
    //var url="${jypath}/processComponent/procdefList";
	$.ajax({
		type: 'post',
        url: url,
	    data: {},
	    dataType:'json',
	    async: false,
	    success: function(data){
			var obj=data.obj;
			var allRole='<option value="">请选择</option>';
			$.each(obj,function(n,v) {
				if(v.procdefId==procdefId){
					allRole=allRole+'<option selected value="'+v.procdefId+'">'+v.procdefName+'</option>';
				}else{
					allRole=allRole+'<option value="'+v.procdefId+'">'+v.procdefName+'</option>';
				}
				
			});
			$("#allProcdef").empty();
			$("#allProcdef").append(allRole);
	    	
	    }
	});
}

</script>
</html>